package com.puzzlebazar.client.util;

import java.util.Iterator;

import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Widget;

public class LayeredPanel extends AbsolutePanel {

	@Override
	public void add(Widget w) {
	    w.removeFromParent();
	    setWidgetPositionImpl(w, 0, 0);
		super.add(w);
		w.setPixelSize( getOffsetHeight(), getOffsetWidth() );
	}	

	@Override
	public void add(Widget w, int left, int top) {
	    throw new UnsupportedOperationException(
	        "This panel does not support positioned add()");
	}

	@Override
	public void setWidth(String width) {
		super.setWidth(width);
	    Iterator<Widget> it = iterator();
	    while (it.hasNext()) {
	      Widget widget = it.next();
	      widget.setWidth( width );
	    }
	}

	@Override
	public void setHeight(String height) {
		super.setHeight(height);
	    Iterator<Widget> it = iterator();
	    while (it.hasNext()) {
	      Widget widget = it.next();
	      widget.setHeight( height );
	    }
	}
}
